<template>
	<view class="order_admin_view">
		<view class="order_item" v-for="item in dataList">
			<view class="flex_center_center pt1">
				<view class="l_l">
					订单编号：{{item.order_sn}}
				</view>
				<view class="l_r">
					{{calcStatus(item.status)}}
				</view>
			</view>
			<view class="flex_center_center pt2">
				<view class="l_l">
					志愿评估：1次
				</view>
				<view class="l_r">
					￥{{item.order_amount}}
				</view>
			</view>
			<view class="flex_center_center pt3">
				<view class="l_l">
					下单时间：{{item.createtime}}
				</view>
				
			</view>
			<view class="o_btns" v-if="item.status == 'unpaid'">
			<!-- <view class="o_btns"> -->
				<view class="btn no" @click="toQuxiao(item.id)">
					取消支付
				</view>
				<view class="btn blue" @click="toPayPage(item.id)">
					立即支付
				</view>
			</view>
			<view class="o_btns" v-if="item.status == 'completed' || item.status == 'paid'">
				<view class="btn blue" @click="pingguRes(item.id)">
					查看评估结果
				</view>
				<view class="btn blue" @click="moniRes(item.eid)">
					模拟填报结果
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList:[],
				page:1,
				isCanUp:true,
			};
		},
		onReachBottom(){
		    let that = this
		    //每次上拉加载的数据比上一次多十个
			if(this.isCanUp){
				++this.page;
				setTimeout(()=>{
					that.getData()
				},200)
			}
		},
		onShow() {
			this.getData()
		},
		methods:{
			toQuxiao(id){
				
				let this_ = this;
				uni.showModal({
					title: '提示',
					content: '是否确认取消该订单?',
					success: function (res) {
						if (res.confirm) {
							this_.$queryApi("post","/school.order/cancel", {
								id
							}, res => {
								this_.page = 1;
								this_.getData()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
				
				
			},
			toPayPage(id){
				uni.navigateTo({
					url:"/pages/order/order?orderId="+id
				})
			},
			calcStatus(val){
				if(val == "closed"){
					return "交易关闭"
				}else
				if(val == "cancel"){
					return "已取消"
				}else
				if(val == "unpaid"){
					return "未支付"
				}else
				if(val == "paid"){
					return "已支付"
				}else
				if(val == "completed"){
					return "已完成"
				}
			},
			getData(){
				uni.showLoading()
				this.$queryApi("post","/school.order/index", {
					pagesize:10,
					page:this.page
				}, res => {
					console.log(res,"订单列表")
				
					let kongList = res.data.data;
					if(this.page == 1){
						this.dataList =  kongList;
					}else{
						this.dataList =  [...this.dataList,...kongList];
					}
					if(res.data.current_page >= res.data.last_page){
						this.isCanUp = false
					}else{
						this.isCanUp = true
					}
					setTimeout(()=>{
						uni.hideLoading()
					},500)
				},"","noMsg")
			},
			moniRes(id){
				uni.navigateTo({
					url:"/pages/order/moni?eid="+id
				})
			},
			pingguRes(id){
				uni.navigateTo({
					url:"/pages/order/pingGu?orderId="+id
				})
			}
		}
	}
</script>

<style lang="scss">
.order_admin_view{
	padding: 20rpx 30rpx 100rpx;
	.order_item{
		border-radius: 20rpx;
		background-color: #fff;
		padding: 10rpx 20rpx;
		&+.order_item{
			margin-top: 20rpx;
		}
		.pt1{
			font-size: 28rpx;
			padding: 20rpx 0;
			.l_l{
				color: #999;
			}
			.l_r{
				color: #3677F6;
				width: 120rpx;
				text-align: right;
			}
		}
		.pt2{
			padding-top:8rpx;
			.l_l{
				font-size: 32rpx;
				color: #333333;
				font-weight: 400;
			}
			.l_r{
				font-size: 36rpx;
				color: #F93F38;
			}
		}
		.pt3{
			font-size: 28rpx;
			padding: 10rpx 0 20rpx;
			.l_l{
				color: #999;
			}
		}
		.o_btns{
			display: flex;
			justify-content: flex-end;
			padding: 20rpx 0 30rpx;
			border-top: 1rpx solid #F6F6F6;
			.btn{
				padding: 8rpx 22rpx;
				border-radius: 16rpx;
				font-size: 24rpx;
				&+.btn{
					margin-left: 20rpx;
				}
				&.no{
					border: 2rpx solid #999999;
					color: #999;
				}
				&.blue{
					border: 2rpx solid #3677F6;
					color: #3677F6;
				}
			}
		}
	}
}
</style>
